package com.web.controller.api;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.web.annotation.IPAccess;
import com.web.annotation.UserAccess;
import com.web.config.PayConfiguration;
import com.web.dao.*;
import com.web.domain.ApiResponse;
import com.web.dto.*;
import com.web.entity.*;
import com.web.manager.CoreManager;
import com.web.manager.IdCardManager;
import com.web.manager.jpush.SendJPushMessage;
import com.web.pay.*;
import com.web.manager.TokenManager;
import com.web.utils.ChangeBeanNullToStr;
import com.web.utils.InvitedCode;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.json.JSONException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

import static com.web.manager.CoreManager.countTotalVal;
import static java.math.BigDecimal.ROUND_HALF_DOWN;

/**
 * @author FDjavaone
 * @date 2017/8/21
 */

@Slf4j
@RestController
@RequestMapping("api")
public class MemberController {
    @Autowired
    private MemberMapper memberMapper;
    @Autowired
    private AccountMapper accountMapper;
    @Autowired
    private StoreMapper storeMapper;
    @Autowired
    private MessageMapper messageMapper;
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private OrderGoodsMapper orderGoodsMapper;
    @Autowired
    private PoundageConfigMapper poundageConfigMapper;
    @Autowired
    private ProfitDetailMapper profitDetailMapper;
    @Autowired
    private ConsumptionDetailMapper consumptionDetailMapper;
    @Autowired
    private WithdrawApplyMapper withdrawApplyMapper;
    @Autowired
    private MerchantDetailMapper merchantDetailMapper;
    @Autowired
    private CoreDetailMapper coreDetailMapper;
    @Autowired
    private OriginalDetailMapper originalDetailMapper;
    @Autowired
    private MskDetailMapper mskDetailMapper;
    @Autowired
    private MskBuyOrderMapper mskBuyOrderMapper;
    @Autowired
    private PlatformMapper platformMapper;
    @Autowired
    private PayConfiguration payConfiguration;
    @Autowired
    private RechargeRecordMapper rechargeRecordMapper;
    @Autowired
    private TokenManager tokenManager;
    @Autowired
    private RegionRecordMapper regionRecordMapper;
    @Autowired
    private CoreManager coreManager;
    @Autowired
    private CompanyCompanyMsDetailMapper companyCompanyMsDetailMapper;
    @Autowired
    private CompanyMarketDetailMapper companyMarketDetailMapper;
    @Autowired
    private CompanyPoundageDetailMapper companyPoundageDetailMapper;
    @Autowired
    private CompanyMarketMsDetailMapper companyMarketMsDetailMapper;
    @Autowired
    private CompanyBonusDetailMapper companyBonusDetailMapper;
    @Autowired
    private ProfitConfigMapper profitConfigMapper;
    @Autowired
    private OrderRecordForPlatformMapper orderRecordForPlatformMapper;
    @Autowired
    private CompanyReportMapper companyReportMapper;

    @Resource(name = "stringRedisTemplate")
    private StringRedisTemplate stringRedisTemplate;


    /**
     *用户充值是否达到100
     * */
    @UserAccess
    @RequestMapping("/app/member/rechargeReach")
    public ApiResponse rechargeReach(Member m, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        if (m.getId() == null ) {
            response.setMessage("获取失败，必传值为空！");
            response.setStatus(900001);
        } else {
            BigDecimal value=rechargeRecordMapper.countRecharegeByMid(m.getId());
            if(value==null){
                response.addParams("0");
            }else {
                if (value.compareTo(new BigDecimal("100"))!=-1) {
                    response.setParams("1");
                } else {
                    response.addParams("0");
                }

            }
            response.setMessage("获取成功!");
            response.setStatus(900000);
        }
        return response;
    }

    /**
     * 用户信息获取
     */
    @UserAccess
    @RequestMapping("/app/member/getDetail")
    public ApiResponse getDetail(Member m, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        if (m.getId() == null && (m.getPhone() == null || "".equals(m.getPhone()))) {
            response.setMessage("获取失败，必传值为空！");
            response.setStatus(900001);
        } else {
            Member member = memberMapper.selectByMember(m);
            if (member == null) {
                response.setMessage("查无用户！");
                response.setStatus(900007);
            } else {
                member = (Member) ChangeBeanNullToStr.transfer(member);
                response.addParams(member);
                response.setMessage("查询成功!");
                response.setStatus(900000);
            }

        }
        return response;
    }

    /**
     * 批量用户信息获取
     */
    @UserAccess
    @RequestMapping("/app/member/batchDetail")
    public ApiResponse batchDetail(@RequestBody String jsonStr, HttpServletRequest req, HttpServletResponse resp) throws IOException, JSONException {
        ApiResponse response = new ApiResponse();

        ObjectMapper objectMapper = new ObjectMapper();
        JsonNode rootNode;
        rootNode = objectMapper.readValue(jsonStr, JsonNode.class);
        JsonNode dataNode = rootNode.get("data");
        JSONArray array = JSONArray.fromObject(dataNode.toString());

        List<CycleUserInfo> cycleUserInfo = JSONArray.toList(array, CycleUserInfo.class);
        for (CycleUserInfo user : cycleUserInfo) {
            Member q = new Member();
            q.setPhone(user.getPhone());
            Member member = memberMapper.selectByMember(q);
            if (member != null) {
                if (member.getHeaderImg() == null) {
                    user.setHeaderImg("");
                } else {
                    user.setHeaderImg(member.getHeaderImg());
                }
                if (member.getNickName() == null) {
                    user.setNick("");
                } else {
                    user.setNick(member.getNickName());
                }
            }
        }
        response.addParams(cycleUserInfo);
        response.setMessage("查询成功!");
        response.setStatus(900000);
        return response;
    }

    /**
     * 批量用户信息获取
     */
    @UserAccess
    @RequestMapping("/app/member/batchDetailKey")
    public ApiResponse batchDetailKey(@RequestParam("phones") String phones, HttpServletRequest req, HttpServletResponse resp) throws IOException, JSONException {
        ApiResponse response = new ApiResponse();

        String[] phoneArr = phones.split(",");
        List<CycleUserInfo> cycleUserInfo = new ArrayList<>();
        for (int i = 0; i < phoneArr.length; i++) {
            CycleUserInfo info = new CycleUserInfo();
            info.setPhone(phoneArr[i]);
            cycleUserInfo.add(info);
        }
        for (CycleUserInfo user : cycleUserInfo) {
            Member q = new Member();
            q.setPhone(user.getPhone());
            Member member = memberMapper.selectByMember(q);
            if (member != null) {
                if (member.getHeaderImg() == null) {
                    user.setHeaderImg("");
                } else {
                    user.setHeaderImg(member.getHeaderImg());
                }
                if (member.getNickName() == null) {
                    user.setNick("");
                } else {
                    user.setNick(member.getNickName());
                }
            }
            user = (CycleUserInfo) ChangeBeanNullToStr.transfer(user);

        }
        response.addParams(cycleUserInfo);
        response.setMessage("查询成功!");
        response.setStatus(900000);
        return response;
    }


    @RequestMapping("open/member/verifyInvitedCode")
    public ApiResponse verifyInvitedCode(Member member) {
        ApiResponse response = new ApiResponse();
        Member member1 = memberMapper.selectMyUp(member.getInvitedCode());
        if (member1 == null) {
            response.setStatus(900098);
            response.setMessage("邀请码不合法！请确认邀请码是否正确");
        } else {
            response.setStatus(900000);
            response.setMessage("邀请码验证通过！");
        }
        return response;
    }


    /**
     * 注册
     */
    @RequestMapping("open/member/signUp")
    public ApiResponse signUp(Member member) {
        ApiResponse response = new ApiResponse();
        Member u = memberMapper.selectByMobile(member.getPhone());
        Date date = new Date();
        member.setCreateTime(date);
        member.setModifyTime(date);
        member.setNickName(member.getPhone());
        if (u == null) {
            memberMapper.insertSelective(member);
            Member us = memberMapper.selectByMobile(member.getPhone());
            // 同时创建用户账户表
            Account account = new Account();
            account.setmId(us.getId());
            account.setCreateTime(date);
            account.setModifyTime(date);
            accountMapper.insertSelective(account);

            member.setId(us.getId());
            member.setInviteCode(InvitedCode.toSerialCode(us.getId()));
            memberMapper.updateByPrimaryKeySelective(member);

            UserInfoDto dto = new UserInfoDto();
            //token获取
            String token = tokenManager.login(member.getPhone(), member.getPassword());
            us = (Member) ChangeBeanNullToStr.transfer(us);
            us.setInviteCode(member.getInviteCode());
            try {
                BeanUtils.copyProperties(us, dto);
                dto.setToken(token);

            } catch (Exception e) {
                response.setStatus(900002);
                response.setMessage(e.getMessage());
            }
            response.setMessage("注册成功！");
            response.setParams(dto);
            response.setStatus(900000);
        } else {
            response.setMessage("该手机号已被注册！");
            response.setStatus(900003);
        }
        return response;
    }

    /**
     * 登录
     */
    @RequestMapping("open/member/signIn")
    public ApiResponse signIn(Member member) {
        Member u = memberMapper.selectByMobile(member.getPhone());
        ApiResponse response = new ApiResponse();
        if (u == null) {
            response.setMessage("用户不存在！");
            response.setStatus(900004);
        } else if (u.getPassword().equals(member.getPassword())) {
            if (u.getEnabled() == 1) {
                //token设置
                String token = tokenManager.login(member.getPhone(), member.getPassword());

                UserInfoDto dto = new UserInfoDto();
                u = (Member) ChangeBeanNullToStr.transfer(u);
                try {
                    BeanUtils.copyProperties(u, dto);
                    dto.setToken(token);
                    response.setMessage("登录成功！");
                    response.setStatus(900000);
                    response.setParams(dto);
                } catch (Exception e) {
                    response.setStatus(900005);
                    response.setMessage(e.getMessage());
                }
            } else {
                response.setStatus(900005);
                response.setMessage("用户账号已经被禁用，请联系管理员！");
            }
        } else {
            String undefined = "unde";
            if (undefined.equals(u.getPassword())) {
                response.setStatus(900008);
                response.setMessage("该账号为预创建账号，请补全密码！");
            } else {
                response.setMessage("密码不正确！");
                response.setStatus(900006);
            }
        }
        return response;
    }

    /**
     * 预注册
     */
    @IPAccess
    @RequestMapping("/open/member/preSignUp")
    public ApiResponse preSignUp(Member member, HttpServletRequest req, HttpServletResponse resp) {
        Member u = memberMapper.selectByMobile(member.getPhone());
        Date date = new Date();
        member.setCreateTime(date);
        member.setModifyTime(date);

        ApiResponse response = new ApiResponse();
        if (u == null) {
            member.setPassword("unde");
            member.setNickName(member.getPhone());
            memberMapper.insertSelective(member);
            Member us = memberMapper.selectByMobile(member.getPhone());
            // 同时创建用户账户表
            Account account = new Account();
            account.setmId(us.getId());
            account.setCreateTime(date);
            account.setModifyTime(date);
            accountMapper.insertSelective(account);

            member.setId(us.getId());
            member.setInviteCode(InvitedCode.toSerialCode(us.getId()));
            memberMapper.updateByPrimaryKeySelective(member);

            UserInfoDto dto = new UserInfoDto();
            us = (Member) ChangeBeanNullToStr.transfer(us);
            try {
                BeanUtils.copyProperties(us, dto);
            } catch (Exception e) {
                response.setStatus(900009);
                response.setMessage(e.getMessage());
            }
            response.setMessage("预注册成功！");
            response.setParams(dto);
            response.setStatus(900000);
        } else {
            response.setMessage("该手机号已被注册！");
            response.setStatus(900010);
        }
        return response;
    }

    /**
     * 重置密码
     */
    @RequestMapping("/open/member/resetPassword")
    public ApiResponse resetPassword(Member member) {
        Member u = memberMapper.selectByMobile(member.getPhone());
        ApiResponse response = new ApiResponse();
        if (u == null) {
            response.setMessage("该手机号未注册，请移步注册！");
            response.setStatus(900012);
        } else {
            Date date = new Date();
            Member us = new Member();
            us.setId(u.getId());
            us.setPassword(member.getPassword());
            us.setModifyTime(date);
            memberMapper.updateByPrimaryKeySelective(us);
            response.setMessage("密码重置成功！");
            response.setStatus(900000);
        }
        return response;
    }

    /**
     * 修改头像
     */
    @UserAccess
    @RequestMapping("/app/member/editHeadImg")
    public ApiResponse editHeadImg(Member member, HttpServletRequest req, HttpServletResponse resp) {
        Member m = new Member();
        m.setId(member.getId());
        ApiResponse response = new ApiResponse();
        Date date = new Date();
        m.setModifyTime(date);
        m.setHeaderImg(member.getHeaderImg());
        memberMapper.updateByPrimaryKeySelective(m);
        response.setMessage("头像修改成功！");
        response.setStatus(900000);
        return response;
    }


    /**
     * 消息列表
     */
    @UserAccess
    @RequestMapping("/app/message/messageList")
    public ApiResponse messageList(PageDto pageDto, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
        List<Message> messageList = messageMapper.selectListByMid(pageDto.getId());
        PageInfo page = new PageInfo(messageList);
        response.setParams(page);
        response.setMessage("消息列表获取成功！");
        response.setStatus(900000);
        return response;
    }

    /**
     * 修改昵称
     */
    @UserAccess
    @RequestMapping("/app/member/editNickName")
    public ApiResponse editNickName(Member member, HttpServletRequest req, HttpServletResponse resp) {
        Member m = new Member();
        m.setId(member.getId());
        ApiResponse response = new ApiResponse();
        Date date = new Date();
        m.setModifyTime(date);
        m.setNickName(member.getNickName());
        memberMapper.updateByPrimaryKeySelective(m);
        response.setMessage("昵称修改成功！");
        response.setStatus(900000);
        return response;
    }

    /**
     * 修改性别
     */
    @UserAccess
    @RequestMapping("/app/member/editGender")
    public ApiResponse editGender(Member member, HttpServletRequest req, HttpServletResponse resp) {
        Member m = new Member();
        m.setId(member.getId());
        ApiResponse response = new ApiResponse();
        Date date = new Date();
        m.setModifyTime(date);
        m.setGender(member.getGender());
        memberMapper.updateByPrimaryKeySelective(m);
        response.setMessage("性别修改成功！");
        response.setStatus(900000);
        return response;
    }

    /**
     * 修改密码
     */
    @UserAccess
    @RequestMapping("/app/member/editPassword")
    public ApiResponse editPassword(ResetPassword pwd, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Date date = new Date();
        Member m = new Member();
        m.setId(pwd.getId());
        m.setPassword(pwd.getOldPwd());

        Member v = memberMapper.selectByMember(m);
        if (v == null) {
            response.setMessage("旧密码验证不通过！");
            response.setStatus(900013);
        } else {
            m.setModifyTime(date);
            m.setPassword(pwd.getNewPwd());
            memberMapper.updateByPrimaryKeySelective(m);
            response.setMessage("密码修改成功！");
            response.setStatus(900000);
        }
        return response;
    }

    /**
     * 判断支付密码是否设置过
     */
    @UserAccess
    @RequestMapping("/app/member/verifyHasPayPwd")
    public ApiResponse verifyHasPayPwd(Member member, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Member m = new Member();
        Map map = new HashMap();
        m.setId(member.getId());
        Member v = memberMapper.selectByMember(m);
        if (v.getPayPassword() == null || "".equals(v.getPayPassword())) {
            map.put("is_hasPayPwd", 0);
            response.setMessage("支付密码未设置！");
        } else {
            map.put("is_hasPayPwd", 1);
            response.setMessage("支付密码已设置！");
        }
        response.setParams(map);
        response.setStatus(900000);
        return response;
    }


    /**
     * 验证支付密码
     */
    @UserAccess
    @RequestMapping("/app/member/verifyPayPwd")
    public ApiResponse verifyPayPwd(Member member, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Member m = new Member();
        m.setId(member.getId());
        m.setPayPassword(member.getPayPassword());

        Member v = memberMapper.selectByMember(m);
        if (v == null) {
            response.setMessage("验证不通过！");
            response.setStatus(900014);
        } else {
            response.setMessage("验证通过！");
            response.setStatus(900000);
        }
        return response;
    }

    /**
     * 重置支付密码
     */
    @UserAccess
    @RequestMapping("/app/member/resetPayPwd")
    public ApiResponse resetPayPwd(Member member, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Member m = new Member();
        Date date = new Date();
        m.setId(member.getId());
        m.setPayPassword(member.getPayPassword());
        m.setModifyTime(date);
        memberMapper.updateByPrimaryKeySelective(m);

        response.setMessage("支付密码重置成功！");
        response.setStatus(900000);

        return response;
    }


    /**
     * 实名认证
     */
    @UserAccess
    @RequestMapping("/app/member/authIdCard")
    public ApiResponse authIdCard(Member member, HttpServletRequest req, HttpServletResponse resp) {
        Member m = new Member();
        Date date = new Date();
        Member found = memberMapper.selectByIdentity(member.getIdentityNo());

        if (found == null) {
            ApiResponse checkIdCad = IdCardManager.getInfo(member);
            if (checkIdCad.getStatus() == 900000) {
                m.setId(member.getId());
                m.setName(member.getName());
                m.setIdentityNo(member.getIdentityNo());
                m.setAuthStatus(1);
                m.setModifyTime(date);
                memberMapper.updateByPrimaryKeySelective(m);
            }
            return checkIdCad;
        } else {
            ApiResponse response = new ApiResponse();
            response.setMessage("该身份证信息已经被其他账号实名认证过，不能重复认证！");
            response.setStatus(900099);
            return response;
        }

    }

    /**
     * 忘记支付密码验证身份证接口
     */
    @UserAccess
    @RequestMapping("/app/member/verifyIdCard")
    public ApiResponse verifyIdCard(Member member, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Member m = new Member();
        m.setId(member.getId());
        m.setIdentityNo(member.getIdentityNo());
        Member v = memberMapper.selectByMember(m);
        if (v == null) {
            response.setMessage("验证不通过！");
            response.setStatus(900015);
        } else {
            response.setMessage("验证通过！");
            response.setStatus(900000);
        }
        return response;
    }

    /**
     * 我的团队
     */
    @UserAccess
    @RequestMapping("/app/member/mySubordinate")
    public ApiResponse mySubordinate(PageDto pageDto, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Member member = memberMapper.selectByPrimaryKey(pageDto.getId());
        PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
        //我的一级下线
        List<Member> first = memberMapper.selectByInvitedCode(member.getInviteCode());
        PageInfo page = new PageInfo(first);
        List<MySubordinate> subordinates = new ArrayList<>();
        for (Member f : first) {
            MySubordinate dto = new MySubordinate();
            try {
                BeanUtils.copyProperties(f, dto);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (orderMapper.countOrderByMidAndNotCancel(f.getId()) == 0) {
                dto.setHasBuy(0);
            } else {
                dto.setHasBuy(1);
            }

            Store sto = storeMapper.selectByMid(f.getId());
            if (sto == null) {
                dto.setHasStore(0);
            } else {
                dto.setHasStore(1);
                dto.setStore(sto);
            }

            subordinates.add(dto);
        }
        Map map = new HashMap();
        map.put("list", subordinates);
        map.put("total", page.getTotal());
        response.setParams(map);
        response.setMessage("获取成功！");
        response.setStatus(900000);
        return response;
    }


    /**
     * 发送消息
     */
    @UserAccess
    @RequestMapping("/app/member/sendMessage")
    public ApiResponse sendMessage(Message message, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Date date = new Date();
        message.setCreateTime(date);
        message.setModifyTime(date);
        messageMapper.insertSelective(message);
        //个推信息推送
        SendJPushMessage.jPushByMessage(message);
        response.setMessage("消息发送成功！");
        response.setStatus(900000);
        return response;
    }


    /**
     * 我的订单
     */
    @UserAccess
    @RequestMapping("/app/member/orderList")
    public ApiResponse orderList(PageDto pageDto, HttpServletRequest req, HttpServletResponse resp) throws InvocationTargetException, IllegalAccessException {
        ApiResponse response = new ApiResponse();
        List<Order> orders = new ArrayList<>();
        Order order = new Order();
        order.setmId(pageDto.getId());
        PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
        if (pageDto.getStatus() == 0) {
            //未完成订单
            orders = orderMapper.selectUnfinishOrder(order);
        } else if (pageDto.getStatus() == 1) {
            //已完成订单
            orders = orderMapper.selectFinishOrder(order);
        }
        List<OrderDto> orderDtos = new ArrayList<>();
        for (Order o : orders) {
            OrderDto orderDto = new OrderDto();
            BeanUtils.copyProperties(o, orderDto);
            Store store = storeMapper.selectByPrimaryKey(o.getStoreId());
            orderDto.setStore(store.getMerchantName());
            orderDtos.add(orderDto);
        }
        PageInfo page = new PageInfo(orders);
        page.getList().clear();
        page.getList().addAll(orderDtos);
        response.setParams(page);
        response.setMessage("获取成功！");
        response.setStatus(900000);
        return response;
    }

    /**
     * 确认收货
     */
    @UserAccess
    @RequestMapping("/app/member/confirm")
    public ApiResponse confirmReceive(Order order, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Order cOrder = orderMapper.selectByPrimaryKey(order.getId());
        if (cOrder.getStatus() == 2) {
            Date date = new Date();
            //消费者账户信息
            Account account = accountMapper.selectByMid(cOrder.getmId());
            //消费者信息
            Member member = memberMapper.selectByPrimaryKey(cOrder.getmId());
            //商家店铺信息
            Store store = storeMapper.selectByPrimaryKey(cOrder.getStoreId());
            //商家账户信息
            Account merchantAccount = accountMapper.selectByMid(store.getmId());
            //商户信息
            Member merchant = memberMapper.selectByPrimaryKey(store.getmId());

            Member memberUp = null;
            if (member.getInvitedCode() != null) {
                //用户上线
                memberUp = memberMapper.selectMyUp(member.getInvitedCode());
            }

            Member merchantUp = null;
            if (merchant.getInvitedCode() != null) {
                //商户上线
                merchantUp = memberMapper.selectMyUp(merchant.getInvitedCode());
            }

            //店铺的省市区三级代理商获取
            RegionRecord province = regionRecordMapper.selectProvince(store.getProvince());
            RegionRecord city = regionRecordMapper.selectProvinceAndCity(store.getProvince(), store.getCity());
            RegionRecord region = regionRecordMapper.selectProvinceAndCityAndRegion(store.getProvince(), store.getCity(), store.getRegion());


            //店铺让利比例，小数
            BigDecimal merchantProfitPercent = new BigDecimal(new Double(store.getLevel()) * 10).divide(new BigDecimal("100"), 2, ROUND_HALF_DOWN);


            //总的奖励分配
            BigDecimal totalBonus = new BigDecimal(0);

            //利润分配配置
            ProfitConfig config = profitConfigMapper.selectByPrimaryKey(1L);
            //msk卖出配置
            PoundageConfig poundageConfig = poundageConfigMapper.selectByPrimaryKey(1L);
            //平台账户信息
            Platform platform = platformMapper.selectByPrimaryKey(1L);

            CompanyReport companyReport = new CompanyReport();

            if (cOrder.getPayType() != null && cOrder.getPayType() != 0) {
                if (cOrder.getPayType() == 1) {
                    companyReport.setReserve1("分润消费,订单编号" + cOrder.getOrderNum());
                    companyReport.setReserve2("1");
                } else if (cOrder.getPayType() == 2) {
                    companyReport.setReserve1("货款消费,订单编号" + cOrder.getOrderNum());
                    companyReport.setReserve2("2");
                } else if (cOrder.getPayType() == 3) {
                    companyReport.setReserve1("基数消费,订单编号" + cOrder.getOrderNum());
                    companyReport.setReserve2("3");
                } else if (cOrder.getPayType() == 4) {
                    companyReport.setReserve1("微信消费,订单编号" + cOrder.getOrderNum());
                    companyReport.setReserve2("4");
                } else if (cOrder.getPayType() == 5) {
                    companyReport.setReserve1("支付宝消费,订单编号" + cOrder.getOrderNum());
                    companyReport.setReserve2("5");
                }
            }

            synchronized (this) {

                //核心处理方法
                coreManager.coreOperation(cOrder, cOrder.getTotalPrice().add(cOrder.getTipPrice()), totalBonus, cOrder.getTransferPrice(), config, poundageConfig, platform, member, memberUp, account, merchant, merchantUp
                        , merchantAccount, province, city, region, date, store, companyReport);

            }

            response.setMessage("确认收货成功！");
            response.setStatus(900000);
        } else {
            response.setMessage("确认收货失败！该订单状态不为待收货状态");
            response.setStatus(900201);
        }
        List<Order> orders = orderMapper.selectUnfinishOrder(order);
        response.setParams(orders);
        return response;
    }

    /**
     * 订单商品明细
     */
    @UserAccess
    @RequestMapping("/app/member/orderGoods")
    public ApiResponse orderGoods(Order order, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        List<OrderGoods> orderGoods = orderGoodsMapper.selectByOrderId(order.getId());
        response.setMessage("获取成功！");
        response.setStatus(900000);
        response.setParams(orderGoods);
        return response;
    }


    /**
     * 分润账户首页
     */
    @UserAccess
    @RequestMapping("/app/member/profit")
    public ApiResponse profit(Member member, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Account account = accountMapper.selectByMid(member.getId());
        //Double history = profitDetailMapper.countHistoryByAid(account.getId());
        Member old=memberMapper.selectByPrimaryKey(member.getId());
        //提现审核中金额
        Double freeze = withdrawApplyMapper.countFreezeByMid(account.getmId(),1);

        PoundageConfig poundageConfig = poundageConfigMapper.selectByPrimaryKey(1L);
        Map map = new HashMap();
        map.put("aid", account.getId());
        map.put("bal", account.getProfit().toString());
        map.put("freeze", freeze);

        map.put("history", old.getBonusAmt());
        map.put("withdrawRate", poundageConfig.getProfitWithdraw());
        map.put("transferRate", poundageConfig.getProfitTransfer());
        response.setMessage("获取成功！");
        response.setStatus(900000);
        response.setParams(map);
        return response;
    }

    /**
     * 分润账户明细
     */
    @UserAccess
    @RequestMapping("/app/profit/detail")
    public ApiResponse profit(PageDto pageDto, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        ProfitDetail profitDetail = new ProfitDetail();
        PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
        profitDetail.setaId(pageDto.getId());
        List<ProfitDetail> profitDetails = profitDetailMapper.selectByAid(profitDetail.getaId());
        PageInfo page = new PageInfo(profitDetails);
        response.setParams(page);
        response.setMessage("获取成功！");
        response.setStatus(900000);
        return response;
    }


    /**
     * 分润转账至消费账户
     */
    @UserAccess
    @RequestMapping("/app/profit/profitTransfer")
    public ApiResponse profitTransfer(ProfitTransfer profitTransfer, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Date date = new Date();
        Account account = accountMapper.selectByPrimaryKey(profitTransfer.getAid());
        Member member = memberMapper.selectByPrimaryKey(account.getmId());
        PoundageConfig poundageConfig = poundageConfigMapper.selectByPrimaryKey(1L);
        BigDecimal poundage = profitTransfer.getTransferBal().multiply(poundageConfig.getProfitTransfer()).divide(new BigDecimal(100), 2, ROUND_HALF_DOWN);
        if (account.getProfit().compareTo(poundage.add(profitTransfer.getTransferBal())) == -1) {
            //重新设置转账金额
            profitTransfer.setTransferBal(account.getProfit().divide(poundageConfig.getProfitTransfer().divide(new BigDecimal("100")).add(new BigDecimal("1")), 2, ROUND_HALF_DOWN));
            poundage = account.getProfit().subtract(profitTransfer.getTransferBal());
            response.setMessage("分润账户余额不足！已自动将全部分润余额转至消费账户！");
        } else {
            response.setMessage("转账成功！");
        }
        CompanyReport companyReport = new CompanyReport();
        companyReport.setReserve1("分润转消费基数");
        companyReport.setCreateTime(date);
        companyReport.setModifyTime(date);

        //记录分润记录
        BigDecimal profitRecord = new BigDecimal("0");
        //记录消费基数记录
        BigDecimal consumeRecord = new BigDecimal("0");
        //记录续费记录
        BigDecimal withdrawPoundageRecord = new BigDecimal("0");

        //分润账户余额减少
        companyReport.setProfitBal("-" + poundage.add(profitTransfer.getTransferBal()));
        profitRecord = new BigDecimal(companyReport.getProfitBal());
        companyReport.setProfitBal((companyReport.getProfitBal() != null ? companyReport.getProfitBal() : "") + "\r\n=" + accountMapper.countProfitNum().add(profitRecord));


        account.setProfit(account.getProfit().subtract(poundage.add(profitTransfer.getTransferBal())));

        //消费账户额度增加
        companyReport.setConsumeBal("+" + profitTransfer.getTransferBal());
        consumeRecord = new BigDecimal(companyReport.getConsumeBal());
        companyReport.setConsumeBal((companyReport.getConsumeBal() != null ? companyReport.getConsumeBal() : "") + "\r\n=" + accountMapper.countConsumeNum().add(consumeRecord));

        account.setConsumption(account.getConsumption().add(profitTransfer.getTransferBal()));
        accountMapper.updateByPrimaryKeySelective(account);
        //分润账户明细生成
        ProfitDetail profitDetail = new ProfitDetail();
        profitDetail.setaId(profitTransfer.getAid());
        profitDetail.setDetail("-" + poundage.add(profitTransfer.getTransferBal()) + "(含手续费" + poundage + ")");
        profitDetail.setContent("转账至消费账户");
        profitDetail.setCreateTime(date);
        profitDetail.setModifyTime(date);
        profitDetail.setBal(accountMapper.selectByPrimaryKey(account.getId()).getProfit().toString());
        profitDetail.setFromNum("");
        profitDetail.setName(member.getName());
        profitDetail.setPhone(member.getPhone());
        profitDetailMapper.insertSelective(profitDetail);

        //对应扣除奖金池的金额
        platformMapper.bonusPoolSubstract(poundage.add(profitTransfer.getTransferBal()), 1L);
        CompanyBonusDetail companyBonusDetail = new CompanyBonusDetail();
        companyBonusDetail.setCreateTime(date);
        companyBonusDetail.setModifyTime(date);
        companyBonusDetail.setContent("用户" + member.getName() + member.getPhone() + "分润账户转入消费账户" + profitTransfer.getTransferBal() + "元,手续费：" + poundage + "元。");
        companyBonusDetail.setDetail("-" + poundage.add(profitTransfer.getTransferBal()));
        companyBonusDetail.setBal(platformMapper.selectByPrimaryKey(1L).getBonusPool().toString());
        companyBonusDetail.setFromNum("");
        companyBonusDetail.setDescription("用户" + member.getName() + member.getPhone() + "分润账户转入消费账户" + profitTransfer.getTransferBal() + "元,手续费：" + poundage + "元。");
        companyBonusDetail.setName(member.getName());
        companyBonusDetail.setPhone(member.getPhone());
        companyBonusDetailMapper.insertSelective(companyBonusDetail);


        //公司手续费池资金增加
        companyReport.setWithdrawPoundage("+" + poundage);
        withdrawPoundageRecord = new BigDecimal(companyReport.getWithdrawPoundage());
        companyReport.setWithdrawPoundage(companyReport.getWithdrawPoundage() != null ? (companyReport.getWithdrawPoundage() + "\r\n=" + platformMapper.selectByPrimaryKey(1L).getPoundagePool().add(withdrawPoundageRecord)) : "");

        companyReport.setTotal(profitRecord.add(consumeRecord).add(withdrawPoundageRecord).toString() + "\n\r=" + countTotalVal(companyReport));

        platformMapper.poundagePoolAdd(poundage, 1L);
        CompanyPoundageDetail companyPoundageDetail = new CompanyPoundageDetail();
        companyPoundageDetail.setCreateTime(date);
        companyPoundageDetail.setModifyTime(date);
        companyPoundageDetail.setContent("用户" + member.getName() + "分润账户转账消费账户,产生手续费,公司手续费池增加");
        companyPoundageDetail.setDetail("+" + poundage);
        companyPoundageDetail.setBal(platformMapper.selectByPrimaryKey(1L).getPoundagePool().toString());
        companyPoundageDetail.setFromNum("");
        companyPoundageDetail.setDescription("分润账户转账消费账户手续费收益增加");
        companyPoundageDetail.setName(member.getName());
        companyPoundageDetail.setPhone(member.getPhone());
        companyPoundageDetailMapper.insertSelective(companyPoundageDetail);


        //消费账户明细生成
        ConsumptionDetail consumptionDetail = new ConsumptionDetail();
        consumptionDetail.setaId(profitTransfer.getAid());
        consumptionDetail.setDetail("+" + profitTransfer.getTransferBal());
        consumptionDetail.setContent("分润账户转入");
        consumptionDetail.setCreateTime(date);
        consumptionDetail.setModifyTime(date);
        consumptionDetail.setBal(accountMapper.selectByMid(account.getmId()).getConsumption().toString());
        consumptionDetail.setFromNum("");
        consumptionDetail.setName(member.getName());
        consumptionDetail.setPhone(member.getPhone());
        consumptionDetailMapper.insertSelective(consumptionDetail);
        account.setModifyTime(date);

        companyReportMapper.insertSelective(companyReport);

        response.setStatus(900000);
        return response;
    }

    /**
     * 分润账户提现
     */
    @UserAccess
    @RequestMapping("/app/profit/profitWithdraw")
    public ApiResponse profitWithdraw(WithdrawApply withdrawApply, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Date date = new Date();
        Account account = accountMapper.selectByMid(withdrawApply.getmId());
        Member member = memberMapper.selectByPrimaryKey(withdrawApply.getmId());
        PoundageConfig poundageConfig = poundageConfigMapper.selectByPrimaryKey(1L);
        BigDecimal poundage = withdrawApply.getAmt().multiply(poundageConfig.getProfitWithdraw()).divide(new BigDecimal(100), 2, ROUND_HALF_DOWN);
        if (account.getProfit().compareTo(poundage.add(withdrawApply.getAmt())) == -1) {
            withdrawApply.setAmt(account.getProfit().divide(poundageConfig.getProfitWithdraw().divide(new BigDecimal("100")).add(new BigDecimal("1")), 2, ROUND_HALF_DOWN));
            poundage = account.getProfit().subtract(withdrawApply.getAmt());
            response.setMessage("分润账户余额不足！已自动发起所有可提现余额申请！");

        } else {
            response.setMessage("提现申请成功！");
        }


        //分润账户余额先审核中 提现金额和手续费
        CompanyReport companyReport = new CompanyReport();
        companyReport.setReserve1("分润提现审核中");
        companyReport.setCreateTime(date);
        companyReport.setModifyTime(date);
        companyReport.setReduce(withdrawApply.getAmt().toString());
        BigDecimal profitRecord = new BigDecimal("0");

        companyReport.setProfitBal("-" + poundage.add(withdrawApply.getAmt()));
        profitRecord = new BigDecimal(companyReport.getProfitBal());
        companyReport.setProfitBal((companyReport.getProfitBal() != null ? companyReport.getProfitBal() : "") + "\r\n=" + accountMapper.countProfitNum().add(profitRecord));

        companyReport.setTotal(profitRecord.toString() + "\n\r=" + countTotalVal(companyReport));

        companyReportMapper.insertSelective(companyReport);

        account.setProfit(account.getProfit().subtract(poundage.add(withdrawApply.getAmt())));
        account.setModifyTime(date);
        accountMapper.updateByPrimaryKeySelective(account);
        //分润账户明细生成（在后台确认已经打款时再添加）
        ProfitDetail profitDetail = new ProfitDetail();
        profitDetail.setaId(account.getId());
        profitDetail.setDetail("-" + poundage.add(withdrawApply.getAmt()) + "(含手续费" + poundage + ")");
        profitDetail.setContent("提现申请审核中");
        profitDetail.setCreateTime(date);
        profitDetail.setModifyTime(date);
        profitDetail.setBal(accountMapper.selectByPrimaryKey(account.getId()).getProfit().toString());
        profitDetail.setFromNum("");
        profitDetail.setName(member.getName());
        profitDetail.setPhone(member.getPhone());
        profitDetailMapper.insertSelective(profitDetail);

        withdrawApply.setCreateTime(date);
        withdrawApply.setModifyTime(date);
        withdrawApply.setType(1);
        withdrawApply.setPoundageRate(poundageConfig.getProfitWithdraw());
        withdrawApply.setPoundage(poundage);
        withdrawApply.setRecordId(profitDetail.getId());
        withdrawApplyMapper.insertSelective(withdrawApply);

        response.setStatus(900000);
        return response;
    }

    /**
     * 消费账户首页
     */
    @UserAccess
    @RequestMapping("/app/member/consumption")
    public ApiResponse consumption(Member member, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Account account = accountMapper.selectByMid(member.getId());
        Map map = new HashMap();
        map.put("aid", account.getId());
        map.put("bal", account.getConsumption().toString());
        response.setMessage("获取成功！");
        response.setStatus(900000);
        response.setParams(map);
        return response;
    }

    /**
     * 消费账户明细
     */
    @UserAccess
    @RequestMapping("/app/consumption/detail")
    public ApiResponse consumptionDetail(PageDto pageDto, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        ConsumptionDetail consumptionDetail = new ConsumptionDetail();
        PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
        consumptionDetail.setaId(pageDto.getId());
        List<ConsumptionDetail> consumptionDetails = consumptionDetailMapper.selectByAid(consumptionDetail.getaId());
        PageInfo page = new PageInfo(consumptionDetails);
        response.setParams(page);
        response.setMessage("获取成功！");
        response.setStatus(900000);
        return response;
    }

    /**
     * 商户货款首页
     */
    @UserAccess
    @RequestMapping("/app/member/merchantPayment")
    public ApiResponse merchantPayment(Member member, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Account account = accountMapper.selectByMid(member.getId());
        //店铺信息
        Store store = storeMapper.selectByMid(member.getId());
        Double total = 0.0;
        Double transfer = 0.0;
        if (store != null) {
            total = orderRecordForPlatformMapper.countTotalBal(store.getId());
            transfer = orderRecordForPlatformMapper.countTransfer(store.getId());
            if (total == null) {
                total = 0.0;
            }
            if (transfer == null) {
                transfer = 0.0;
            }
        }

        PoundageConfig poundageConfig = poundageConfigMapper.selectByPrimaryKey(1L);
        //提现审核中金额
        Double freeze = withdrawApplyMapper.countFreezeByMid(account.getmId(),2);

        Map map = new HashMap();
        map.put("aid", account.getId());
        map.put("bal", account.getMerchantPayment().toString());
        map.put("freeze", freeze);
        map.put("total", total);
        map.put("transfer", transfer);
        map.put("merchantWithDraw", poundageConfig.getMerchantWithdraw());
        response.setMessage("获取成功！");
        response.setStatus(900000);
        response.setParams(map);
        return response;
    }


    /**
     * 商户货款明细
     */
    @UserAccess
    @RequestMapping("/app/merchantPayment/detail")
    public ApiResponse merchantPaymentDetail(PageDto pageDto, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
        List<MerchantDetail> merchantDetails = merchantDetailMapper.selectByAid(pageDto.getId());
        PageInfo page = new PageInfo(merchantDetails);
        response.setParams(page);
        response.setMessage("获取成功！");
        response.setStatus(900000);
        return response;
    }

    /**
     * 商家货款转账至消费账户
     */
    @UserAccess
    @RequestMapping("/app/merchantPayment/transfer")
    public ApiResponse merchantPaymentTransfer(ProfitTransfer profitTransfer, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Date date = new Date();
        Account account = accountMapper.selectByPrimaryKey(profitTransfer.getAid());
        Store store = storeMapper.selectByMid(account.getmId());
        Member member = memberMapper.selectByPrimaryKey(account.getmId());
        if (account.getMerchantPayment().compareTo(profitTransfer.getTransferBal()) == -1) {
            profitTransfer.setTransferBal(account.getMerchantPayment());
            response.setMessage("商户货款余额不足！自动转账所有商户货款余额到消费账户！");
        } else {
            response.setMessage("转账成功！");
        }

        CompanyReport companyReport = new CompanyReport();
        companyReport.setReserve1("分润转消费基数");
        companyReport.setCreateTime(date);
        companyReport.setModifyTime(date);

        //记录货款记录
        BigDecimal profitRecord = new BigDecimal("0");
        //记录消费基数记录
        BigDecimal consumeRecord = new BigDecimal("0");
        //记录续费记录
        BigDecimal withdrawPoundageRecord = new BigDecimal("0");

        //商户货款余额减少
        companyReport.setUnWithdraw("-" + profitTransfer.getTransferBal());
        profitRecord = new BigDecimal(companyReport.getUnWithdraw());
        companyReport.setUnWithdraw((companyReport.getUnWithdraw() != null ? companyReport.getUnWithdraw() : "") + "\r\n=" + accountMapper.countMerchantNum().add(profitRecord));


        account.setMerchantPayment(account.getMerchantPayment().subtract(profitTransfer.getTransferBal()));
        //消费账户额度增加

        companyReport.setConsumeBal("+" + profitTransfer.getTransferBal());
        consumeRecord = new BigDecimal(companyReport.getConsumeBal());
        companyReport.setConsumeBal((companyReport.getConsumeBal() != null ? companyReport.getConsumeBal() : "") + "\r\n=" + accountMapper.countConsumeNum().add(consumeRecord));


        companyReport.setTotal(profitRecord.add(consumeRecord).toString() + "\n\r=" + countTotalVal(companyReport));

        companyReportMapper.insertSelective(companyReport);

        account.setConsumption(account.getConsumption().add(profitTransfer.getTransferBal()));
        accountMapper.updateByPrimaryKeySelective(account);
        //商户货款明细生成
        MerchantDetail merchantDetail = new MerchantDetail();
        merchantDetail.setaId(profitTransfer.getAid());
        merchantDetail.setDetail("-" + profitTransfer.getTransferBal());
        merchantDetail.setContent("转账至消费账户");
        merchantDetail.setCreateTime(date);
        merchantDetail.setModifyTime(date);
        merchantDetail.setBal(accountMapper.selectByPrimaryKey(account.getId()).getMerchantPayment().toString());
        merchantDetail.setName(member.getName());
        merchantDetail.setPhone(member.getPhone());
        merchantDetail.setFromNum("");
        if (store != null) {
            merchantDetail.setStore(store.getMerchantName());
            merchantDetail.setStoreId(store.getId());
        }
        merchantDetail.setType(4);
        merchantDetail.setTotalBal(accountMapper.countMerchantNum().toString());
        merchantDetailMapper.insertSelective(merchantDetail);


        //消费账户明细生成
        ConsumptionDetail consumptionDetail = new ConsumptionDetail();
        consumptionDetail.setaId(profitTransfer.getAid());
        consumptionDetail.setDetail("+" + profitTransfer.getTransferBal());
        consumptionDetail.setContent("商家货款转入");
        consumptionDetail.setCreateTime(date);
        consumptionDetail.setModifyTime(date);
        consumptionDetail.setBal(accountMapper.selectByMid(account.getmId()).getConsumption().toString());
        consumptionDetail.setFromNum("");
        consumptionDetail.setName(member.getName());
        consumptionDetail.setPhone(member.getPhone());
        consumptionDetailMapper.insertSelective(consumptionDetail);
        account.setModifyTime(date);


        response.setStatus(900000);
        return response;
    }

    /**
     * 商家货款提现
     */
    @UserAccess
    @RequestMapping("/app/merchantPayment/withdraw")
    public ApiResponse merchantPaymentWithdraw(WithdrawApply withdrawApply, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Date date = new Date();
        Account account = accountMapper.selectByMid(withdrawApply.getmId());
        Member member = memberMapper.selectByPrimaryKey(withdrawApply.getmId());
        Store store = storeMapper.selectByMid(member.getId());
        PoundageConfig poundageConfig = poundageConfigMapper.selectByPrimaryKey(1L);
        BigDecimal poundage = withdrawApply.getAmt().multiply(poundageConfig.getMerchantWithdraw()).divide(new BigDecimal(100), 2, ROUND_HALF_DOWN);
        if (account.getMerchantPayment().compareTo(poundage.add(withdrawApply.getAmt())) == -1) {
            withdrawApply.setAmt(account.getMerchantPayment().divide(poundageConfig.getMerchantWithdraw().divide(new BigDecimal("100")).add(new BigDecimal("1")), 2, ROUND_HALF_DOWN));
            poundage = account.getMerchantPayment().subtract(withdrawApply.getAmt());
            response.setMessage("商户货款余额不足！自动提现所有可提现商户货款！");
        } else {
            response.setMessage("提现申请成功！");
        }

        CompanyReport companyReport = new CompanyReport();
        companyReport.setReserve1("货款提现审核中");
        companyReport.setCreateTime(date);
        companyReport.setModifyTime(date);
        companyReport.setReduce(withdrawApply.getAmt().toString());
        BigDecimal profitRecord = new BigDecimal("0");

        companyReport.setUnWithdraw("-" + poundage.add(withdrawApply.getAmt()));
        profitRecord = new BigDecimal(companyReport.getUnWithdraw());
        companyReport.setUnWithdraw((companyReport.getUnWithdraw() != null ? companyReport.getUnWithdraw() : "") + "\r\n=" + accountMapper.countMerchantNum().add(profitRecord));

        companyReport.setTotal(profitRecord.toString() + "\n\r=" + countTotalVal(companyReport));

        companyReportMapper.insertSelective(companyReport);


        //商家货款余额先审核中 提现金额
        accountMapper.merchantPaymentSubtract(poundage.add(withdrawApply.getAmt()), account.getId());
        //商家货款明细生成 审核中款项
        MerchantDetail merchantDetail = new MerchantDetail();
        merchantDetail.setaId(account.getId());
        merchantDetail.setDetail("-" + poundage.add(withdrawApply.getAmt()) + "(含手续费" + poundage + ")");
        merchantDetail.setContent("提现申请审核中");
        merchantDetail.setCreateTime(date);
        merchantDetail.setModifyTime(date);
        merchantDetail.setBal(accountMapper.selectByPrimaryKey(account.getId()).getMerchantPayment().toString());
        merchantDetail.setName(member.getName());
        merchantDetail.setPhone(member.getPhone());
        merchantDetail.setFromNum("");
        if (store != null) {
            merchantDetail.setStore(store.getMerchantName());
            merchantDetail.setStoreId(store.getId());
        }
        merchantDetail.setType(3);
        merchantDetail.setTotalBal(accountMapper.countMerchantNum().toString());
        merchantDetailMapper.insertSelective(merchantDetail);

        withdrawApply.setCreateTime(date);
        withdrawApply.setModifyTime(date);
        withdrawApply.setType(2);
        withdrawApply.setPoundageRate(poundageConfig.getMerchantWithdraw());
        withdrawApply.setPoundage(poundage);
        withdrawApply.setRecordId(merchantDetail.getId());
        withdrawApplyMapper.insertSelective(withdrawApply);

        response.setStatus(900000);
        return response;
    }


    /**
     * 睿积分明细
     */
    @UserAccess
    @RequestMapping("/app/corePoints/detail")
    public ApiResponse corePointsDetail(PageDto pageDto, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        CoreDetail coreDetail = new CoreDetail();
        Account account = accountMapper.selectByMid(pageDto.getId());
        PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
        coreDetail.setaId(account.getId());
        List<CoreDetail> coreDetails = coreDetailMapper.selectByAid(coreDetail.getaId());
        PageInfo page = new PageInfo(coreDetails);
        Map map = new HashMap();
        map.put("page", page);
        map.put("corePoints", account.getCorePoints());
        response.setParams(map);
        response.setMessage("获取成功！");
        response.setStatus(900000);
        return response;
    }

    /**
     * 原积分账户首页
     */
    @UserAccess
    @RequestMapping("/app/member/originalIntegral")
    public ApiResponse originalIntegral(Member member, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Account account = accountMapper.selectByMid(member.getId());
        Map map = new HashMap();
        map.put("aid", account.getId());
        map.put("bal", account.getOriginalIntegral());
        List<OriginalDetail> originalDetails = originalDetailMapper.selectByAid(account.getId());
        map.put("rows", originalDetails);
        response.setMessage("获取成功！");
        response.setStatus(900000);
        response.setParams(map);
        return response;
    }

    /**
     * MSK账户
     */
    @UserAccess
    @RequestMapping("/app/member/msk")
    public ApiResponse msk(Member member, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Account account = accountMapper.selectByMid(member.getId());
        Map map = new HashMap();
        map.put("aid", account.getId());
        map.put("mskBal", account.getMsk());
        Platform platform = platformMapper.selectByPrimaryKey(1L);
        if (platform.getMarketMsk().compareTo(new BigDecimal("0")) == 0) {
            map.put("nowPrice", 1);
        } else {
            map.put("nowPrice", platform.getMarketFundPool().divide(platform.getMarketMsk(), 2, ROUND_HALF_DOWN));
        }

        //获取用户的，处于挂买的订单
        List<MskBuyOrder> mskBuyOrders = mskBuyOrderMapper.selectByMid(member.getId());
        BigDecimal corePoints = new BigDecimal(0);
        for (MskBuyOrder m : mskBuyOrders) {
            corePoints = corePoints.add(m.getCorePoints());
        }
        map.put("corePoints", corePoints);
        response.setMessage("获取成功！");
        response.setStatus(900000);
        response.setParams(map);
        return response;
    }

    /**
     * msk交易主页
     */
    @UserAccess
    @RequestMapping("/app/msk/mskIndex")
    public ApiResponse mskIndex(Member member, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Account account = accountMapper.selectByMid(member.getId());
        Map map = new HashMap();
        map.put("aid", account.getId());
        map.put("mskBal", account.getMsk());
        Platform platform = platformMapper.selectByPrimaryKey(1L);
        if (platform.getMarketMsk().compareTo(new BigDecimal("0")) == 0) {
            map.put("nowPrice", 1);
        } else {
            map.put("nowPrice", platform.getMarketFundPool().divide(platform.getMarketMsk(), 2, ROUND_HALF_DOWN));
        }
        List<MskBuyOrder> mskBuyOrdersShow = mskBuyOrderMapper.selectAhead13();
        //获取用户的，处于挂买的订单
        List<MskBuyOrder> mskBuyOrders = mskBuyOrderMapper.selectByMid(member.getId());
        BigDecimal corePoints = new BigDecimal(0);
        for (MskBuyOrder m : mskBuyOrders) {
            corePoints = corePoints.add(m.getCorePoints());
        }
        map.put("mskBuyOrdersShow", mskBuyOrdersShow);
        map.put("corePoints", corePoints);
        response.setMessage("获取成功！");
        response.setStatus(900000);
        response.setParams(map);
        return response;
    }

    /**
     * 当前挂单
     */
    @UserAccess
    @RequestMapping("/app/msk/myBuyMskOrders")
    public ApiResponse myBuyMskOrders(PageDto pageDto, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        List<MskBuyOrder> orders = new ArrayList<>();
        MskBuyOrder order = new MskBuyOrder();
        order.setmId(pageDto.getId());
        PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
        if (pageDto.getStatus() == 0) {
            //未完成买入挂单
            orders = mskBuyOrderMapper.selectUnfinishOrder(order);
        } else if (pageDto.getStatus() == 1) {
            //已完成买入挂单
            orders = mskBuyOrderMapper.selectFinishOrder(order);
        }
        PageInfo page = new PageInfo(orders);
        response.setParams(page);
        response.setMessage("获取成功！");
        response.setStatus(900000);
        return response;
    }

    /**
     * 卖出msk页面数据获取
     */
    @UserAccess
    @RequestMapping("/app/msk/mskSaleIndex")
    public ApiResponse mskSaleIndex(Member member, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Account account = accountMapper.selectByMid(member.getId());
        Map map = new HashMap();
        map.put("aid", account.getId());
        map.put("mskBal", account.getMsk());
        Platform platform = platformMapper.selectByPrimaryKey(1L);
        if (platform.getMarketMsk().compareTo(new BigDecimal("0")) == 0) {
            map.put("nowPrice", 1);
        } else {
            map.put("nowPrice", platform.getMarketFundPool().divide(platform.getMarketMsk(), 2, ROUND_HALF_DOWN));
        }
        response.setMessage("获取成功！");
        response.setStatus(900000);
        response.setParams(map);
        return response;
    }

    /**
     * 卖出msk接口
     */
    @UserAccess
    @RequestMapping("/app/msk/mskSale")
    public ApiResponse mskSale(SaleMskDto dto, HttpServletRequest req, HttpServletResponse resp) {
        Date date = new Date();
        ApiResponse response = new ApiResponse();
        try {

            synchronized (this) {
                //获取当前平台信息
                Platform platform = platformMapper.selectByPrimaryKey(1L);
                //获取msk交易策略
                PoundageConfig poundageConfig = poundageConfigMapper.selectByPrimaryKey(1L);

                //msk当前市场价格
                BigDecimal newPrice = platform.getMarketFundPool().divide(platform.getMarketMsk(), 2, ROUND_HALF_DOWN);

                //判断当前msk市场价格是否需要裂变
                if (newPrice.compareTo(new BigDecimal("2")) != -1) {
                    throw new RuntimeException("裂变保护期，挂买交易停止，请稍后再操作");
                }


                //,市场msk账户减少对应数量，公司msk账户增加对应数量，按市场价格从市场资金池中取出对应金额，
                // 按配置分别加到用户的分润账户和消费账户，手续费加入到公司利润账户
                Member member = memberMapper.selectByPrimaryKey(dto.getId());

                Account account = accountMapper.selectByMid(dto.getId());
                if (account.getMsk().compareTo(dto.getNum()) == -1) {
                    throw new RuntimeException("账户可卖出MSK数量不足！");
                }
                //用户的msk账户减少对应msk
                accountMapper.mskSubtract(dto.getNum(), account.getId());
                MskDetail mskDetail = new MskDetail();
                mskDetail.setTransactionNum(dto.getNum());
                mskDetail.setTransactionPrice(newPrice);
                mskDetail.setModifyTime(date);
                mskDetail.setCreateTime(date);
                mskDetail.setType(2);
                mskDetail.setContent("卖出");
                mskDetail.setDetail("MS:-" + dto.getNum());
                mskDetail.setaId(account.getId());
                mskDetail.setBal(accountMapper.selectByPrimaryKey(account.getId()).getMsk().toString());
                mskDetail.setName(member.getName());
                mskDetail.setPhone(member.getPhone());
                mskDetailMapper.insertSelective(mskDetail);

                //公司msk账户增加对应数量msk
                platformMapper.companyMskAdd(dto.getNum(), 1L);
                CompanyCompanyMsDetail companyCompanyMsDetail = new CompanyCompanyMsDetail();
                companyCompanyMsDetail.setCreateTime(date);
                companyCompanyMsDetail.setModifyTime(date);
                companyCompanyMsDetail.setContent("用户" + member.getName() + "主动卖出MS,公司MS增加");
                companyCompanyMsDetail.setDetail("+" + dto.getNum());
                companyCompanyMsDetail.setBal(platformMapper.selectByPrimaryKey(1L).getCompanyMsk().toString());
                companyCompanyMsDetail.setDescription("用户" + member.getName() + "主动卖出MS,公司MS增加");
                companyCompanyMsDetail.setFromNum("");
                companyCompanyMsDetail.setName(member.getName());
                companyCompanyMsDetail.setPhone(member.getPhone());
                companyCompanyMsDetailMapper.insertSelective(companyCompanyMsDetail);

                //市场msk账户减少对应数量msk
                platformMapper.marketMskSubtract(dto.getNum(), 1L);
                CompanyMarketMsDetail companyMarketMsDetail = new CompanyMarketMsDetail();
                companyMarketMsDetail.setCreateTime(date);
                companyMarketMsDetail.setModifyTime(date);
                companyMarketMsDetail.setContent("用户" + member.getName() + "主动卖出MS,市场MS减少");
                companyMarketMsDetail.setDetail("-" + dto.getNum());
                companyMarketMsDetail.setBal(platformMapper.selectByPrimaryKey(1L).getMarketMsk().toString());
                companyMarketMsDetail.setFromNum("");
                companyMarketMsDetail.setName(member.getName());
                companyMarketMsDetail.setPhone(member.getPhone());
                companyMarketMsDetail.setDescription("用户" + member.getName() + "主动卖出MS,市场MS减少");
                companyMarketMsDetailMapper.insertSelective(companyMarketMsDetail);

                CompanyReport companyReport = new CompanyReport();

                companyReport.setCreateTime(date);
                companyReport.setModifyTime(date);
                companyReport.setReserve1("兑换MS");

                BigDecimal withdrawRecord = new BigDecimal("0");
                BigDecimal marketRecord = new BigDecimal("0");
                BigDecimal consumeRecord = new BigDecimal("0");
                BigDecimal profitRecord = new BigDecimal("0");

                //市场资金池扣除对应金额用于支付
                companyReport.setMarketFund("-" + newPrice.multiply(dto.getNum()).setScale(2, ROUND_HALF_DOWN));
                marketRecord = new BigDecimal(companyReport.getMarketFund());
                companyReport.setMarketFund((companyReport.getMarketFund() != null ? companyReport.getMarketFund() : "") + "\r\n=" + platformMapper.selectByPrimaryKey(1L).getMarketFundPool().add(marketRecord));


                platformMapper.marketFundPoolSubtract(newPrice.multiply(dto.getNum()).setScale(2, ROUND_HALF_DOWN), 1L);
                CompanyMarketDetail companyMarketDetail = new CompanyMarketDetail();
                companyMarketDetail.setCreateTime(date);
                companyMarketDetail.setModifyTime(date);
                companyMarketDetail.setContent("用户" + member.getName() + "主动卖出MS,市场资金支付，余额减少");
                companyMarketDetail.setDetail("-" + newPrice.multiply(dto.getNum()).setScale(2, ROUND_HALF_DOWN));
                companyMarketDetail.setName(member.getName());
                companyMarketDetail.setPhone(member.getPhone());
                companyMarketDetail.setFromNum("");
                companyMarketDetail.setBal(platformMapper.selectByPrimaryKey(1L).getMarketFundPool().toString());
                companyMarketDetail.setDescription("用户" + member.getName() + "主动卖出MS,市场资金支付，余额减少");

                companyMarketDetailMapper.insertSelective(companyMarketDetail);

                //手续费
                BigDecimal pound = newPrice.multiply(dto.getNum()).multiply(poundageConfig.getMskSale()).divide(new BigDecimal("100"), 2, ROUND_HALF_DOWN);
                //利润账户
                BigDecimal profitbal = newPrice.multiply(dto.getNum()).multiply(poundageConfig.getMskSaleP()).divide(new BigDecimal("100"), 2, ROUND_HALF_DOWN);

                //公司手续费池资金增加
                companyReport.setWithdrawPoundage("+" + pound);
                withdrawRecord = new BigDecimal(companyReport.getWithdrawPoundage());
                companyReport.setWithdrawPoundage("+" + withdrawRecord + "\n\r=" + platformMapper.selectByPrimaryKey(1L).getPoundagePool().add(withdrawRecord));


                platformMapper.poundagePoolAdd(pound, 1L);
                CompanyPoundageDetail companyPoundageDetail = new CompanyPoundageDetail();
                companyPoundageDetail.setCreateTime(date);
                companyPoundageDetail.setModifyTime(date);
                companyPoundageDetail.setContent("用户" + member.getName() + "主动卖出MS,产生手续费,公司手续费池增加");
                companyPoundageDetail.setDetail("+" + pound);
                companyPoundageDetail.setBal(platformMapper.selectByPrimaryKey(1L).getPoundagePool().toString());
                companyPoundageDetail.setFromNum("");
                companyPoundageDetail.setDescription("MS裂变卖出手续费收益增加");
                companyPoundageDetail.setName(member.getName());
                companyPoundageDetail.setPhone(member.getPhone());
                companyPoundageDetailMapper.insertSelective(companyPoundageDetail);


                //用户利润账户增加
                companyReport.setProfitBal("+" + profitbal);
                profitRecord = new BigDecimal(companyReport.getProfitBal());
                companyReport.setProfitBal("+" + profitRecord + "\n\r=" + accountMapper.countProfitNum().add(profitRecord));


                accountMapper.profitAdd(profitbal, account.getId());
                ProfitDetail profitDetailUp = new ProfitDetail();
                profitDetailUp.setModifyTime(date);
                profitDetailUp.setCreateTime(date);
                profitDetailUp.setContent("卖出MS");
                profitDetailUp.setDetail("+" + profitbal);
                profitDetailUp.setaId(account.getId());
                profitDetailUp.setBal(accountMapper.selectByPrimaryKey(account.getId()).getProfit().toString());
                profitDetailUp.setFromNum("");
                profitDetailUp.setName(member.getName());
                profitDetailUp.setPhone(member.getPhone());
                profitDetailMapper.insertSelective(profitDetailUp);
                //用户消费账户增加
                companyReport.setConsumeBal("+" + newPrice.multiply(dto.getNum()).subtract(pound).subtract(profitbal));
                consumeRecord = new BigDecimal(companyReport.getConsumeBal());
                companyReport.setConsumeBal("+" + consumeRecord + "\n\r=" + accountMapper.countConsumeNum().add(consumeRecord));


                accountMapper.consumptionAdd(newPrice.multiply(dto.getNum()).subtract(pound).subtract(profitbal), account.getId());
                ConsumptionDetail consumptionDetail = new ConsumptionDetail();
                consumptionDetail.setModifyTime(date);
                consumptionDetail.setCreateTime(date);
                consumptionDetail.setContent("卖出MS");
                consumptionDetail.setDetail("+" + newPrice.multiply(dto.getNum()).subtract(pound).subtract(profitbal));
                consumptionDetail.setaId(account.getId());
                consumptionDetail.setBal(accountMapper.selectByMid(account.getmId()).getConsumption().toString());
                consumptionDetail.setFromNum("");
                consumptionDetail.setName(member.getName());
                consumptionDetail.setPhone(member.getPhone());
                consumptionDetailMapper.insertSelective(consumptionDetail);

                companyReport.setTotal(marketRecord.add(withdrawRecord).add(profitRecord).add(consumeRecord).toString() + "\n\r=" + countTotalVal(companyReport));
                companyReportMapper.insertSelective(companyReport);
                response.setMessage("MSK成功卖出！");
                response.setStatus(900000);
            }

        } catch (Exception e) {
            e.printStackTrace();
            response.setMessage(e.getMessage());
            response.setStatus(900802);
        }

        return response;
    }


    /**
     * msk明细
     */
    @UserAccess
    @RequestMapping("/app/msk/detail")
    public ApiResponse mskDetail(PageDto pageDto, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        MskDetail mskDetail = new MskDetail();
        PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
        mskDetail.setaId(pageDto.getId());
        List<MskDetail> mskDetails = mskDetailMapper.selectByAid(mskDetail.getaId());
        PageInfo page = new PageInfo(mskDetails);
        response.setParams(page);
        response.setMessage("获取成功！");
        response.setStatus(900000);
        return response;
    }

    /**
     * 支付时分润账户余额，消费账户余额，商户货款账户余额获取
     */
    @UserAccess
    @RequestMapping("/app/bal/aheadPay")
    public ApiResponse mskDetail(Member member, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Account account = accountMapper.selectByMid(member.getId());
        response.setParams(account);
        response.setMessage("获取成功！");
        response.setStatus(900000);
        return response;
    }


    /**
     * 手机号变更
     */
    @UserAccess
    @RequestMapping("/app/member/changeMobile")
    public ApiResponse changeMobile(Member member, HttpServletRequest req, HttpServletResponse resp) {
        ApiResponse response = new ApiResponse();
        Date date = new Date();
        Member old = memberMapper.selectByPrimaryKey(member.getId());
        Member newM = memberMapper.selectByMobile(member.getPhone());
        if (newM != null) {
            if (newM.getAuthStatus() != 1) {
                //手机号存在注册，且未实名制，替换手机号清除该用户，清除登录token
                String token = stringRedisTemplate.opsForValue().get(old.getPhone());
                //清除redis缓存
                stringRedisTemplate.delete(token);
                stringRedisTemplate.delete(old.getPhone());

                memberMapper.deleteByPrimaryKey(newM.getId());
                member.setModifyTime(date);
                memberMapper.updateByPrimaryKeySelective(member);

                response.setMessage("手机号已经替换成功，请用新的手机号重新登录！");
                response.setStatus(900000);
            } else {
                //手机号存在注册，已经实名制，无法更换手机号
                response.setMessage("该手机号已被注册且实名过，无法替换！");
                response.setStatus(900800);
            }
        } else {
            //手机号未注册，更换手机号，清除登录token
            String token = stringRedisTemplate.opsForValue().get(old.getPhone());
            //清除redis缓存
            stringRedisTemplate.delete(token);
            stringRedisTemplate.delete(old.getPhone());
            member.setModifyTime(date);
            memberMapper.updateByPrimaryKeySelective(member);
            response.setMessage("手机号已经替换成功，请用新的手机号重新登录！");
            response.setStatus(900000);
        }
        return response;
    }


    /**
     * 消费账户充值
     */
    @UserAccess
    @RequestMapping("/app/consume/recharge")
    public ApiResponse recharge(RechargeDto rechargeDto, HttpServletRequest req, HttpServletResponse resp) throws Exception {
        ApiResponse response = new ApiResponse();
        //Account account = accountMapper.selectByMid(member.getId());
        // response.setParams(account);
        Member member = memberMapper.selectByPrimaryKey(rechargeDto.getId());
        String orderNum = "REC";
        synchronized (this) {
            Date date = new Date();
            orderNum += date.getTime();
            if (rechargeDto.getType() == 1) {
                //支付宝支付订单创建
                AliPayDto aliPayDto = new AliPayDto();
                aliPayDto.setPayAppid(payConfiguration.getAli().getAppid());
                aliPayDto.setPayUrl(payConfiguration.getAli().getUrl());
                aliPayDto.setPaySelfSecret(payConfiguration.getAli().getSelfSecret());
                aliPayDto.setPayPublicSecret(payConfiguration.getAli().getPublicSecret());
                aliPayDto.setPayPublicSecret2(payConfiguration.getAli().getPublicSecret2());
                //3分钟不支付，交易结束
                aliPayDto.setTimeOutExpress("3m");
                aliPayDto.setOutTradeNo(orderNum);
                aliPayDto.setSubject("消费账户充值");
                //测试0.01元 支付宝 单位元
                //aliPayDto.setTotalAmount(String.valueOf(0.01));
                aliPayDto.setTotalAmount(String.valueOf(rechargeDto.getAmount()));
                aliPayDto.setBody("消费账户充值支付总额" + rechargeDto.getAmount());
                aliPayDto.setNotifyUrl(payConfiguration.getAli().getCallback() + "/api/open/ali_notify_recharge");
                PayResponse aliResponse = AliPayManage.mg.aliPayApp(aliPayDto);
                if (aliResponse.getStatus() == 1) {

                    RechargeRecord rechargeRecord = new RechargeRecord();
                    rechargeRecord.setAmount(rechargeDto.getAmount());
                    rechargeRecord.setCreateTime(date);
                    rechargeRecord.setmId(rechargeDto.getId());
                    rechargeRecord.setModifyTime(date);
                    rechargeRecord.setOutTradeNo(orderNum);
                    rechargeRecord.setStatus(0);
                    rechargeRecord.setType(1);
                    rechargeRecord.setName(member.getName());
                    rechargeRecord.setPhone(member.getPhone());
                    rechargeRecordMapper.insertSelective(rechargeRecord);

                    response.setStatus(900000);
                    response.setMessage(aliResponse.getMessage());
                    response.setParams(aliResponse.getParams());
                    return response;
                } else {
                    response.setStatus(900901);
                    response.setMessage("支付宝支付订单创建失败！");
                    return response;
                }

            } else {
                //微信支付
                WxPayDto wxPayDto = new WxPayDto();
                wxPayDto.setAppid(payConfiguration.getWx().getAppId());
                wxPayDto.setMch_id(payConfiguration.getWx().getMchId());
                wxPayDto.setSignKey(payConfiguration.getWx().getSignKey());
                wxPayDto.setTrade_type("APP");
                //测试0.01元 微信支付的单位 1分
                wxPayDto.setTotal_fee(String.valueOf(rechargeDto.getAmount().multiply(new BigDecimal(100)).intValue()));

                /**设置3分钟过期*/
                SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
                Calendar expired = Calendar.getInstance();
                expired.set(Calendar.MINUTE, expired.get(Calendar.MINUTE) + 3);
                wxPayDto.setTime_expire(sdf.format(expired.getTime()));

                log.info("超时时间："+wxPayDto.getTime_expire());

                wxPayDto.setBody("订单" + orderNum);
                wxPayDto.setOut_trade_no(orderNum);
                wxPayDto.setSpbill_create_ip("220.191.96.232");
                wxPayDto.setNotify_url(payConfiguration.getWx().getCallback() + "/api/open/wx_notify_recharge");
                PayResponse apiResponse = WxPayManage.mg.wxPay(wxPayDto);
                if (apiResponse.getStatus() == 1) {

                    RechargeRecord rechargeRecord = new RechargeRecord();
                    rechargeRecord.setAmount(rechargeDto.getAmount());
                    rechargeRecord.setCreateTime(date);
                    rechargeRecord.setmId(rechargeDto.getId());
                    rechargeRecord.setModifyTime(date);
                    rechargeRecord.setOutTradeNo(orderNum);
                    rechargeRecord.setStatus(0);
                    rechargeRecord.setType(2);
                    rechargeRecord.setName(member.getName());
                    rechargeRecord.setPhone(member.getPhone());
                    rechargeRecordMapper.insertSelective(rechargeRecord);

                    response.setStatus(900000);
                    response.setMessage(apiResponse.getMessage());
                    response.setParams(apiResponse.getParams());
                    return response;
                } else {
                    response.setStatus(900901);
                    response.setMessage("微信支付订单创建失败!");
                    return response;
                }

            }
        }
    }

}
